home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 22 / PC Actual CD 22.iso / progs / Netobj / CDK / NetObjectsFusionCDK5_97.exe / _SETUP.1 / TickerTapeComp.java < prev    next >
Encoding:
Java Source  |  1997-05-14  |  6.2 KB  |  244 lines

  1. import ComponentApp;
  2. import java.lang.Integer;
  3.  
  4. public class TickerTapeComp extends ComponentApp
  5. {
  6.     int          Speed;
  7.     int          Frame;
  8.     int          Background;
  9.     int          LED;
  10.     int numImages;
  11.     int MaxImages;
  12.     DAssetManager assetMan;
  13.     DDrawJava theJavaApplet; 
  14.     String[] imageNames;
  15.     int[] imageURLs;
  16.     
  17.     public void onCopy()
  18.     {
  19.         String[] imageNamesOld = imageNames;
  20.         int[] imageURLsOld = imageURLs;
  21.  
  22.         allocateImageArray(MaxImages);
  23.         for(int cnt=0;cnt<numImages;cnt++)
  24.         {
  25.             imageNames[cnt] = new String(imageNamesOld[cnt]);
  26.             if(imageURLsOld[cnt] !=0 && imageURLsOld[cnt] != -1) 
  27.             {
  28.                 imageURLs[cnt] = imageURLsOld[cnt];
  29.                 assetMan.CopyAsset(imageURLsOld[cnt]);
  30.             }
  31.         }
  32.     }
  33.  
  34.     protected void finalize()
  35.     {
  36.         for(int cnt=0;cnt<numImages;cnt++)
  37.         {
  38.             if(imageURLs[cnt] !=0 && imageURLs[cnt] != -1)
  39.                 assetMan.RemoveAsset(imageURLs[cnt]);
  40.         }
  41.     }
  42.     public String onInstall(DAssetManager cam, String codeBase) 
  43.     { 
  44.         MaxImages=50;
  45.         assetMan = cam;
  46.         return "Ticker Tape";
  47.     }
  48.     
  49.     public void onInspect(CStringArray Names,CStringArray Types)
  50.     {
  51.         Names.Set("Number of Messages");
  52.         Types.Set(typeJavaCollection);
  53.         for(int cnt=0; cnt<numImages; cnt++)
  54.         {
  55.             Names.Set("Text for Message "+Integer.toString(cnt+1));
  56.             Types.Set(typeString);
  57.             Names.Set("URL for Message "+Integer.toString(cnt+1));
  58.             Types.Set(typeLink);
  59.         }
  60.         Names.Set("Speed");
  61.         Types.Set(typeJavaCollection);
  62.         Names.Set("Frame Color");
  63.         Types.Set(typeJavaColor);
  64.         Names.Set("Background Color");
  65.         Types.Set(typeJavaColor);
  66.         Names.Set("LED Color");
  67.         Types.Set(typeJavaColor);
  68.     }
  69.     
  70.     public String PropertyListener(String Event,String Value,int Get, int propIndex, IDInspector insp) 
  71.     {
  72.         if (Get == 1)
  73.         {
  74.             if (Event.compareTo("Number of Messages") == 0)
  75.             {
  76.                 return Integer.toString(numImages);
  77.             }
  78.             else if (Event.compareTo("Speed") == 0)
  79.             {
  80.                 return Integer.toString(Speed);
  81.             }
  82.             else if (Event.compareTo("Frame Color") == 0)
  83.             {
  84.                 return Integer.toString(Frame);
  85.             }
  86.             else if (Event.compareTo("Background Color") == 0)
  87.             {
  88.                 return Integer.toString(Background);
  89.             }
  90.             else if (Event.compareTo("LED Color") == 0)
  91.             {
  92.                 return Integer.toString(LED);
  93.             }
  94.             else
  95.             {
  96.                 for(int cnt=0; cnt<numImages; cnt++)
  97.                 {
  98.                     if (Event.compareTo("Text for Message "+Integer.toString(cnt+1))==0)
  99.                         return new String(imageNames[cnt]);
  100.                     if (Event.compareTo("URL for Message "+Integer.toString(cnt+1))==0)
  101.                         return Integer.toString(imageURLs[cnt]);
  102.                 }
  103.             }
  104.         }
  105.         else
  106.         {
  107.             if (Event.compareTo("Number of Messages") == 0)
  108.             {
  109.                 numImages=Integer.parseInt(Value,10);
  110.                 if(numImages>MaxImages)
  111.                     numImages=MaxImages;
  112.             }
  113.             else if (Event.compareTo("Speed") == 0)
  114.             {
  115.                 Speed = Integer.parseInt(Value,10);
  116.             
  117.                 if (Speed < 1)
  118.                     Speed = 1;
  119.                 else if (Speed > 50)
  120.                     Speed = 50;
  121.  
  122.                 theJavaApplet.AddParam("speed",typeInt,Integer.toString(Speed));
  123.             }
  124.             else if (Event.compareTo("Frame Color") == 0)
  125.             {
  126.                 Frame = Integer.parseInt(Value,10);
  127.                 SetColor("framecolor",Frame);
  128.             }
  129.             else if (Event.compareTo("Background Color") == 0)
  130.             {
  131.                 Background = Integer.parseInt(Value,10);
  132.                 SetColor("backcolor",Background);
  133.             }
  134.             else if (Event.compareTo("LED Color") == 0)
  135.             {
  136.                 LED = Integer.parseInt(Value,10);
  137.                 SetColor("ledcolor",LED);
  138.             }
  139.             else 
  140.             {
  141.                 for(int cnt=0; cnt<numImages; cnt++)
  142.                 {
  143.                     if (Event.compareTo("Text for Message "+Integer.toString(cnt+1))==0)
  144.                     {    
  145.                         imageNames[cnt]=Value;
  146.                         theJavaApplet.AddParam("text"+Integer.toString(cnt+1),typeString,Value);
  147.                     }
  148.                     if (Event.compareTo("URL for Message "+Integer.toString(cnt+1))==0)
  149.                     {
  150.                         imageURLs[cnt]=Integer.parseInt(Value,10);
  151.                         String theURL;
  152.                         if(imageURLs[cnt]!=-1)
  153.                         {
  154.                             theURL=assetMan.GetAssetLocation(imageURLs[cnt], 0, IFileNameStyle.DosName);
  155.                         }
  156.                         else
  157.                         {
  158.                             theURL="";
  159.                         }
  160.                         theJavaApplet.AddParam("link"+Integer.toString(cnt+1),typeString,theURL);                                
  161.                     }
  162.                 }
  163.             }    
  164.         }
  165.         return "";
  166.     }
  167.     
  168.     void allocateImageArray(int n) {
  169.  
  170.         imageNames=new String[n];
  171.         imageURLs=new int[n];
  172.         for(int cnt=0;cnt< n;cnt++)
  173.         {
  174.             imageURLs[cnt]=-1;
  175.             imageNames[cnt] = "";
  176.         }
  177.     }
  178.     
  179.     public void onDrop(IDLayout layout, IDRect r, int fDrop) 
  180.     {
  181.         //
  182.         // we only process drop for now
  183.         //
  184.         if (fDrop != ActivateState.Drop)  // the first time the component is dropped
  185.             return;
  186.         
  187.         numImages=2;
  188.         
  189.         Speed      = 25;
  190.         Frame      = 6;
  191.         Background = 0;
  192.         LED        = 5;
  193.  
  194.         allocateImageArray(MaxImages);
  195.         theJavaApplet = new DDrawJava();
  196.         theJavaApplet.setImageFile(theJavaApplet.getCodeBase() + "TickerTape.jpg");
  197.         theJavaApplet.setStretch(PictureStretchMode.DRAW_STRETCHED);
  198.         theJavaApplet.setAppletFileName(theJavaApplet.getCodeBase() + "TickerTape.class");                
  199.         theJavaApplet.SetPositionRect(r.getLeft(), r.getTop(), r.getRight(), r.getBottom());
  200.         layout.AddObject(theJavaApplet);
  201.  
  202.     }
  203.     
  204.     public void onUnInstall(DAssetManager cam) 
  205.     {
  206.     }
  207.     
  208.     public void onPublish(DAssetManager asm, int context)
  209.     {
  210.     }
  211.     
  212.     private void SetColor(String VarName,int SetVal)
  213.     {
  214.         if (SetVal == 0)
  215.             theJavaApplet.AddParam(VarName,typeString,"black");
  216.         else if (SetVal == 1)
  217.             theJavaApplet.AddParam(VarName,typeString,"blue");
  218.         else if (SetVal == 2)
  219.             theJavaApplet.AddParam(VarName,typeString,"cyan");
  220.         else if (SetVal == 3)
  221.             theJavaApplet.AddParam(VarName,typeString,"darkGray");
  222.         else if (SetVal == 4)
  223.             theJavaApplet.AddParam(VarName,typeString,"gray");
  224.         else if (SetVal == 5)
  225.             theJavaApplet.AddParam(VarName,typeString,"green");
  226.         else if (SetVal == 6)
  227.             theJavaApplet.AddParam(VarName,typeString,"lightGray");
  228.         else if (SetVal == 7)
  229.             theJavaApplet.AddParam(VarName,typeString,"magenta");
  230.         else if (SetVal == 8)
  231.             theJavaApplet.AddParam(VarName,typeString,"orange");
  232.         else if (SetVal == 9)
  233.             theJavaApplet.AddParam(VarName,typeString,"pink");
  234.         else if (SetVal == 10)
  235.             theJavaApplet.AddParam(VarName,typeString,"red");
  236.         else if (SetVal == 11)
  237.             theJavaApplet.AddParam(VarName,typeString,"white");
  238.         else if (SetVal == 12)
  239.             theJavaApplet.AddParam(VarName,typeString,"yellow");
  240.     }
  241.     
  242.     
  243. }
  244.